<script setup lang="ts">
let range = ref(100)
let autoSize = ref('auto-fit')
let widthP = computed(() => {
  return range.value + '%'
})
</script>

<template>
<div class="wrap">
  <div class="form">
    <label for="grid-template-columns">grid-template-columns:</label>
    <div>repeat(
      <select v-model="autoSize" name="grid-template-columns" id="">
        <option value="auto-fit">auto-fit</option>
        <option value="auto-fill">auto-fill</option>
      </select>
      , 120px)
    </div>
  </div>

  <section>
    <div class="container">
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
    </div>
    <form>
      <input type="range" min="0" max="100" v-model="range">
    </form>
  </section>
  <p>手动滑块，调整容器的宽度！</p>

</div>
</template>

<style scoped lang="scss">
.wrap {
  width: 100vw;
  min-height: 100vh;
  font-family: "Exo", Arial, sans-serif;
  background-color: #557;
  color: #fff;
  display: grid;
  place-content: center;
  padding: 1rem;
  gap: 2rem;

  .form {
    display: flex;
    align-items: center;
  }

  section {
    width: 1000px;
    margin: 0 auto;

    display: flex;
    min-height: 200px;
    justify-content: space-between;
    /*   align-items: center; */
    flex-direction: column;

    gap: 2rem;
    box-shadow: 0 0 0 6px rgb(217 210 10 / 9%);
    border-radius: 4px;

    .container {
      --width: v-bind(widthP);
      --auto-size: v-bind(autoSize);

      width: var(--width);
      padding: 10px;
      display: grid;
      gap: 10px;
      grid-template-columns: repeat(var(--auto-size), 120px);

      outline: 1px dashed #f36;
      counter-reset: item;

      .item {
        counter-increment: item;
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 160px;
        background-color: #f36;
        color: #000;

        &:nth-child(1) {
          background-color:  #f1c2c6;
        }
        &:nth-child(2) {
          background-color:  #dac2f1;
        }
        &:nth-child(3) {
          background-color:  #ccf1c2;
        }
        &:nth-child(4) {
          background-color:  #c2e9f1;
        }
        &:nth-child(5) {
          background-color:  #9f10ae;
        }
        &:nth-child(6) {
          background-color:  #f44336;
        }
        &::before {
          content: counter(item);
          font-family: "Bungee Shade", cursive;
          font-size: 3.5rem;
        }
      }
    }

    form {
      width: 100%;

      input[type="range"] {
        width: 100%;
      }
    }
  }

}
</style>
